<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : Noise</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">
  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName">Noise</p>
    	
       <p class="linkListHeader">Fields</p>
       <p class="linkList">
           
    <a href="noise_field_amplitude.html" title="Patch to this to control the amplitude of the noise with another UGen.">amplitude</a><br/>
    
    <a href="noise_field_offset.html" title="Patch to this to offset the value of the noise by a fixed value.">offset</a><br/>
    
	   </p>
   
    	
       <p class="linkListHeader">Methods</p>
       <p class="linkList">
           
    <a href="noise_method_channelcount.html" title="Returns the number of channels this UGen has been configured to generate.">channelCount ( )</a><br/>
    
    <a href="noise_method_getlastvalues.html" title="Return the last values generated by this UGen. This will most often be
 used by sub-classes when pulling data from their inputs.">getLastValues ( )</a><br/>
    
    <a href="noise_method_gettint.html" title="Returns the current Noise.Tint in use">getTint ( )</a><br/>
    
    <a href="noise_method_patch.html" title="Send the output of this UGen to another UGen, UGenInput, or AudioOutput.">patch ( )</a><br/>
    
    <a href="noise_method_printinputs.html" title="Prints all inputs connected to this UGen (for debugging)">printInputs ( )</a><br/>
    
    <a href="noise_method_samplerate.html" title="Returns the sample rate of this UGen.">sampleRate ( )</a><br/>
    
    <a href="noise_method_setchannelcount.html" title="Let this UGen know how many channels of audio you will be asking it for.">setChannelCount ( )</a><br/>
    
    <a href="noise_method_setsamplerate.html" title="Set the sample rate for this UGen.">setSampleRate ( )</a><br/>
    
    <a href="noise_method_settint.html" title="Set the Noise.Tint to use.">setTint ( )</a><br/>
    
    <a href="noise_method_tick.html" title="Generates one sample frame for this UGen.">tick ( )</a><br/>
    
    <a href="noise_method_unpatch.html" title="Unpatch this UGen from an AudioOutput or other UGen.">unpatch ( )</a><br/>
    
	   </p>
   
    </td>
    <td class="mainText border-left">
    	A UGen that can generate White, Pink, or Red/Brown noise.
    	<p class="memberSectionHeader">Constructors</p>
    	<pre><em>Constructor for white noise. 
 By default, the amplitude will be 1 and the tint will be WHITE.</em>
Noise()
<em>Constructor for white noise of the specified amplitude.</em>
Noise(float amplitude)
<em>Constructor for noise of the specified tint with an amplitude of 1.0.</em>
Noise(Noise.Tint noiseType)
<em>Constructor for noise of a specific tint with a specified amplitude.</em>
Noise(float amplitude, Noise.Tint noiseType)
<em>Constructor for noise of a specific tint with a specified amplitude and offset.</em>
Noise(float amplitude, float offset, Noise.Tint noiseType)
</pre>
    	
   <p class="memberSectionHeader">Parameters</p>
   
        <span class="parameterName">amplitude</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: the amplitude of the noise</span><br/>
    
        <span class="parameterName">noiseType</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">Noise.Tint: specifies the tint of the noise 
 		(Noise.Tint.WHITE, Noise.Tint.PINK, Noise.Tint.RED, Noise.Tint.BROWN)</span><br/>
    
        <span class="parameterName">offset</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: the value that should be added to the noise to offset the "center"</span><br/>
    
   
    	<p class="memberSectionHeader">Related</p>
    	<A href="ugen_class_ugen.html">UGen</A><BR>
<A href="noise.tint_class_noise.tint.html">Noise.Tint</A><BR>

    	<p class="memberSectionHeader">Example</p>
    	<pre>/* noiseExample&lt;br/>
   is a example of how to use noise in an instrument.
   It is shows the different types of noise using a slightly
   interesting bouncing cyan bar.  This is also an example of how
   to connect the visual aspects of Processing and Minim.
   &lt;p>
   For more information about Minim and additional features, 
   visit http://code.compartmental.net/minim/
   &lt;p>
   author:Anderson Mills&lt;br/>
   Anderson Mills's work was supported by numediart (www.numediart.org).
*/

// import everything necessary to make sound.
import ddf.minim.*;
import ddf.minim.ugens.*;

// create all of the variables that will need to be accessed in
// more than one methods (setup(), draw(), stop()).
Minim minim;
AudioOutput out;

// just plays a burst of noise of the specified tint and amplitude
class NoiseInstrument implements Instrument
{
  // create all variables that must be used throughout the class
  Noise myNoise;
  
  // constructors for the intsrument
  NoiseInstrument( float amplitude, Noise.Tint noiseTint )
  {
    // create new instances of any UGen objects as necessary
    // white noise is used for this instrument
    myNoise = new Noise( amplitude, noiseTint );
  }
  
  // every instrument must have a noteOn( float ) method
  void noteOn( float dur )
  {
    myNoise.patch( out );
  }
  
  // every instrument must have a noteOff() method
  void noteOff()
  {
    // unpatch the output 
    // this causes the entire instrument to stop calculating sampleframes
    // which is good when the instrument is no longer generating sound.
    myNoise.unpatch( out );
  }
}

// used as instruments
NoiseInstrument myWhiteNoise, myPinkNoise, myRedNoise;
// used for the drawing
color noiseColor;
int xa;
int xDir;
int iFlip;

// setup is run once at the beginning
void setup()
{
  size( 400, 200, P2D );
  
  // initialize the minim and out objects
  minim = new Minim(this);
  // the small buffer size of 512 is chosen to minimize delay between the visual and audio
  // this may cause problems with buffer underruns on slower systems
  out = minim.getLineOut(Minim.MONO, 512);
  // define the notes that will be played
  myWhiteNoise = new NoiseInstrument( 0.5, Noise.Tint.WHITE );
  myPinkNoise = new NoiseInstrument( 0.5, Noise.Tint.PINK );
  myRedNoise = new NoiseInstrument( 0.5, Noise.Tint.RED );
  // define some variables for making the drawing
  xa = 10;
  xDir = 1;
  iFlip = 0;
  noiseColor = color( 255, 255, 255 );
}

// draw is run many times
void draw()
{
  // erase the window to black
  background(0);
  // move the bouncing line along one step
  xa = xa + xDir*4;
  
  // if the line is at the right border, make a noise and go left
  if ( xa > width-1 )
  {
    xDir = -1;
    // if the iFlip flag is zero make white noise
    if ( 0 == iFlip )
    {
    out.playNote( 0, 1.5, myWhiteNoise );
    noiseColor = color( 255, 255, 255 );
    // otherwise make the iFlip flag red noise
    } else
    {
      out.playNote( 0, 1.5, myRedNoise );
      noiseColor = color( 255, 0, 0 );
    }
    // flip the value of the iFlip flag
    iFlip = 1 - iFlip;
  }
  // if the line is at the left border, make a noise and go right
  if ( xa  &lt; 1 )
  {
    xDir = 1;
    out.playNote( 0, 1.5, myPinkNoise );
    noiseColor = color( 255, 128, 128 );
  }
  
  // color the drawing the same as the noise tint
  stroke( noiseColor );
  for(int i = 0; i &lt; out.bufferSize() - 1; i++)
  {
    float x1 = map(i, 0, out.bufferSize(), 0, width);
    float x2 = map(i+1, 0, out.bufferSize(), 0, width);
    line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
    line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
  }
  
  // make the cyan bouncing line and it's inverse
  stroke( 0, 255, 255 );
  line( xa, 0, xa, 100 );
  line( width-xa, 100, width-xa, 200 );
}
</pre>
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>